import configparser
import os
import sys

class AdsConfig:
    _instance = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(AdsConfig, cls).__new__(cls)
            cls._instance._config = configparser.ConfigParser()
            # 检查文件是否存在
            base_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
            file_path = os.path.join(base_dir, 'configs/ads_config.ini')
            if not os.path.exists(file_path):
                print(f"配置文件 {file_path} 未找到。")
                raise FileNotFoundError(f"配置文件 {file_path} 未找到。")
            cls._instance._config.read(file_path, 'utf-8')
        return cls._instance

    def get(self, section, option):
        return self._config.get(section, option)

    def get_int(self, section, option):
        return self._config.getint(section, option)

    def get_boolean(self, section, option):
        return self._config.getboolean(section, option)

    def set(self, section, option, value):
        self._config.set(section, option, value)